<template>
	<view>
		<view class="pl25 pr25">
			<view class="pt30 pb30 bb flex flex-ac flex-pj">
				<text class="ft14">真实姓名</text>
				<input type="text" class="it1 pl30 pr30 ft13 c666" placeholder="请输入真实姓名" v-model="userName" />
			</view>
			<view class="pt30 pb30 bb flex flex-ac flex-pj">
				<text class="ft14">手机号</text>
				<input type="number" class="it1 pl30 pr30 ft13 c666" placeholder="请输入手机号" v-model="userPhone" />
			</view>
			<view class="pt30 pb30 bb flex flex-ac flex-pj">
				<text class="ft14">身份证号</text>
				<input type="idcard" class="it1 pl30 pr30 ft13 c666" placeholder="请输入身份证号" v-model="userCard" />
			</view>
		</view>
		<view class="bottomBtn ftc">
			<view class="bottomBtncon bgfff">
				<text class="cfff btns ct ftc block" @click="submit">提交修改</text>
			</view>
		</view>
		<uni-popup ref="popup" type="message">
		    <uni-popup-message :type="warnType" :message=warnMessage :duration="warnTime"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				usrUserId:'',//用户id
				userName:'',//真实姓名
				userPhone:'',//手机号
				userCard:'',//身份证号
				warnMessage:'错误',//消息内容
				warnType:'warn',//消息类型  success/warn/info/error
				warnTime:1000,//消息提醒延长时间
				usrUserId:''//用户表id
			};
		},
		onLoad(option) {
			this.usrUserId = option.userId;
		},
		onShow() {},
		methods: {
			submit(){
				var that = this;
				if(that.verification()){
					var parm = {};
					parm.name=that.userName;
					parm.phone=that.userPhone;
					parm.isdefault=that.userCard;
					parm.usrUserId=that.usrUserId;
					uni.showModal({
					    title: '提示',
					    content: '是否确定提交信息',
					    success: function (res) {
					        if (res.confirm) {
					            uni.request({
					            	url: 'https://app.mzmzb.com/application-usrapp/wx/updateUsrInfo.tz',
					            	data: parm,
									header : {'content-type':'application/x-www-form-urlencoded'},
					            	method:"POST",
					            	success: (item) => {
										if(item.data.success){
											that.warnMessage = '修改成功';
											that.warnType = 'success';
											that.$refs.popup.open();
											setTimeout(()=>{
												//首页的跳转
												uni.reLaunch({
													url: '/pages/user/index?userId='+that.usrUserId
												});
											},3000)
										}else{
											that.warnMessage = item.data.errMsg;
											that.warnType = 'error';
											that.warnTime  = 3000;
											that.$refs.popup.open();
										}
					            	},
					            	fail(error) {
										that.warnMessage = '修改失败';
										that.warnType = 'error';
										that.$refs.popup.open();
					            	},
					            })
					        } else if (res.cancel) {
					            
					        }
					    }
					});
				};
			},
			//数据验证
			verification(){
				 if(!this.userName){
				 	this.warnMessage = '姓名不能为空';
				 	this.$refs.popup.open();
				 	return false;
				 }
				 if(!this.phone){
				 	this.userPhone = '电话号码不能为空';
				 	this.$refs.popup.open();
				 	return false;
				 }
				 if(!this.userCard){
				 	this.warnMessage = '身份证号不能为空';
				 	this.$refs.popup.open();
				 	return false;
				 }
				
				return true;
			}
		}
	};
</script>

<style lang="less">
	text{
		display: inline-block;
		width: 120rpx;
		height: 1.4rem;
	}
	.bottomBtn{
		position: relative;
		height: 125rpx;
		width: 100%;
		.bottomBtncon{
			position: fixed;
			width: 100%;
			z-index: 10;
			left: 0;
			height: 125rpx;
			bottom: 0;
			background: #FFFFFF;
			.btns{
				width: 660rpx;
				height: 100rpx;
				line-height: 100rpx;
				border-radius: 10rpx;
				background: #74a6fd;
			}
		}
	}
</style>
